<template lang="pug">
//- 楼层项
el-dialog(title="楼层项" :visible.sync="flooritem" :before-close="close" @selection-change="hsc" append-to-body)
    SetFloorItemList
    el-row
        el-button(type="primary" icon="el-icon-plus" @click="newadd") 新增
    el-table(:data="dt" style="width:100%" height="350" tooltip-effect="dark")
        el-table-column(type="selection" width="55")
        el-table-column(prop="imageUrl" label="图片")
            template(slot-scope="scope")
                img(:src="scope.row.imageUrl" style="width:100px")
        el-table-column(prop="type" label="链接类型")
            template(slot-scope="scope")
                el-tag(v-if="scope.row.type == 2" type="gray") url
                el-tag(v-if="scope.row.type == 1" type="primary") 商品
                el-tag(v-if="scope.row.type == 3" type="info") 分类
        el-table-column(prop="sort" label="排序")
        el-table-column(label="操作")
            template(slot-scope="scope")
                el-button(size="mini" @click="hd(scope.$index, scope.row)") 编辑
                el-button(size="mini" type="danger" @click="del(scope.$index, scope.row)") 删除
</template>
<script>
import SetFloorItemList from '../SetWxConfig/SetFloorItemList'
import {Table} from 'element-ui'
    export default{
        data(){
            return{
                flooritem:false,
                dt:[],
                selection:[],
                floorId:-1,
                loading:false
            }
        },
        components:{
            SetFloorItemList
        },
        computed:{
            getstate(){
                return this.$store.state.flootgoodlistclass;
            },
            getchange(){
                return this.$store.state.floorgoodlist;
            },
            getdialog(){
                return this.$store.state.floor;
            }
        },
        watch:{
            getstate(val){//监听当前弹窗的打开关闭
                this.flooritem=val
            },
            getchange(v){//监听获取的数据
                // this.dt=[]
                // this.dt=v.floorItemList
                this.floorId=v.floorId
                
                this.getData()
            },
            getdialog(v){//监听弹窗
                if(!v){
                    this.$store.state.floor=true
                    var _this=this
                    var pp=new URLSearchParams()
                    pp.append('floorId',this.floorId)
                    axios.get('/listFloorItems.do',{params:pp}).then(r=>{
                        if(r.data.code==200){
                            _this.dt=[]
                            _this.dt=[].concat(r.data.response.listFloorItems)
                            
                        }
                    })
                }
            }
        },
        methods:{
            close(){//关闭
                this.$store.state.flootgoodlistclass = false
            },
            hd(i,r){//编辑
                this.$store.commit('ChangeFloorGoodList2',r)
            },
            del(i,r){//删除
                var _this=this
                this.$confirm('确认删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var p=new URLSearchParams()
                    p.append('floorItemId',r.floorItemId)
                    axios.get('/deleteByFloorItemId.do',{params:p}).then(r=>{
                        // console.log('删除楼层项',r)
                        if(r.data.code==200){
                            this.$message({
                                message:"删除成功",
                                type:'success'
                            })
                            _this.getData()
                        }else{
                            this.$message({
                                message:r.data.message,
                                type:'info'
                            })
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });          
                }); 
            },
            hsc(v){//获取选中的数据
                this.selection=v
            },
            newadd(){//打开新增的弹窗
                this.$store.commit('ChangeFloorGoodList2',this.floorId)
            },
            getData(){//获取数据
                var _this=this
                var pp=new URLSearchParams()
                pp.append('floorId',this.floorId)
                axios.get('/listFloorItems.do',{params:pp}).then(r=>{
                    if(r.data.code==200){
                        _this.dt=[]
                        _this.dt=[].concat(r.data.response.listFloorItems)
                    }else{
                        _this.$message.error(r.data.message)
                    }
                })
            }
        }
    }
</script>